//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.ruoyi.live.excel.service;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.builder.ExcelWriterSheetBuilder;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.fastjson2.JSONObject;
import org.springframework.stereotype.Service;

import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ExamScoreService {
    public ExamScoreService() {
    }

    public void exportScore(List<List<Object>> list, List<List<String>> heads, HttpServletResponse response) throws IOException {
        try {
            String fileName = URLEncoder.encode("得分表", "UTF-8");
            response.setContentType("application/vnd.ms-excel");
            response.setCharacterEncoding("utf-8");
            response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
            ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).build();
            WriteSheet sheet = ((ExcelWriterSheetBuilder) EasyExcel.writerSheet(0, "得分信息").head(heads)).build();
            excelWriter.write(list, sheet);
            excelWriter.finish();
        } catch (Exception var7) {
            var7.printStackTrace();
            response.reset();
            response.setContentType("application/json");
            response.setCharacterEncoding("utf-8");
            Map<String, String> map = new HashMap();
            map.put("status", "failure");
            map.put("message", "下载文件失败");
            response.getWriter().println(JSONObject.toJSONString(map));
        }

    }
}
